import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @description:线程池创建线程
 * @author:Mr.Cat
 * @create:2021-09-25 11:15
 **/
public class ThreadPool {
    public static void main(String[] args) {
        //提供指定线程数量的线程池
        ExecutorService service= Executors.newFixedThreadPool(10);
        ThreadPoolExecutor service1 = (ThreadPoolExecutor)service;
        //设置线程池的属性
        //service1.setCorePoolSize(15);
        //service1.setKeepAliveTime();

        //执行指定的线程的操作，需要提供实现了Runnable接口实现类的对象
        service.execute(new PoolThread1());//适合适用于Runnable

        //es1.submit(Callable callable);//适用于Callable
        service.shutdown();
    }
}
class PoolThread1 implements Runnable{
    @Override
    public void run() {
        for (int i = 1;i<=100;i++){
            if(i%2==0){
                System.out.println(i);
            }
        }
    }
}

